﻿--[[
   @brief    msg_box_frame_view 
   @author   hqzheng
   @version  1.0
   @date     2017-02-20
--]]

msg_box_frame_view = 
{
    pDialog_ = nil;
    dwRootId_ = 0;
}

function msg_box_frame_view:init()
    base_utility.log("[msg_box_frame_view] init ");
end

function msg_box_frame_view:show(bShow, ext_param)
    if self:is_created() then
        if bShow then
            self.pDialog_:Show(TRUE);
            self.pDialog_:Restore();
            self.pDialog_:BringToTop();
        else
            self.pDialog_:Show(FALSE);
        end
    else
        self:create(ext_param);
    end
end

function msg_box_frame_view:is_created()
    if self.pDialog_ then
        return true;
    else
        return false;
    end
end

function msg_box_frame_view:is_show()
    local showed = false;
    if self.pDialog_ then
        if self.pDialog_:IsVisible() == TRUE then
            showed = true;
        end
    end
    return showed;
end

function msg_box_frame_view:create(ext_param)
    if self.pDialog_ then
        msg_box_frame_model.is_already_exist = true;
        return true;
    end

    if nil == ext_param then
        ext_param = {};
    end

    self.dwRootId_ = layout_mgr.restore_layout("message_box.tpf");
    
    if self.dwRootId_ ~= 0 then
        self.pDialog_ = ui_utility.get_ctrl_ptr_by_id(self.dwRootId_);
        local pWebCtrl = ui_utility.get_ctrl_ptr_by_cid(CID_WEB_CTRL_FOR_MESSAGE_BOX);

        local social =
            base_utility.get_component_adapter("ISocial_network",
                "ierd_tgp.social_network.Get_social_network_adapter();");
        local webkit_switch = social:get_webkit_switch();
        local url_param = ext_param.url_param or "";
        local url = "/platform/msgbox/msgbox.html" .. url_param;
        local dst_url = web_utility.make_ptlogin_url(url, "https");
        local ui_str, str_holder = U8toCUIStr(dst_url);
        if pWebCtrl then
            pWebCtrl:Navigate(ui_str);
        end
        return true;
    else
        base_utility.log("[msg_box_frame_view] msg_box_frame_view error!!!");
        return false;
    end
end

function msg_box_frame_view:hide(uilib, ctrl_id)
    base_utility.log("[msg_box_frame_view] remove msg_box_frame_view tpf");
    ----shadow_helper.destroy_shadow(self.dwRootId_);
    layout_mgr.delay_remove_ctrl(self.dwRootId_);
    self.dwRootId_ = 0;
    self.pDialog_ = nil;
end

function msg_box_frame_view:close()
    self.pDialog_:Show(FALSE);
    ----shadow_helper.destroy_shadow(self.dwRootId_);
end

function msg_box_frame_view:OnNavigateComplete()
    msg_box_frame_view:show(true);
end

function msg_box_frame_view:OnNavigateFailed()
    msg_box_frame_view:show(true);
end

msg_box_frame_view.init();

